home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 12692 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.0 KB  |  47 lines

  1. Path: red.seas.upenn.edu!son
  2. From: son@red.seas.upenn.edu (Sonny)
  3. Newsgroups: comp.lang.c++
  4. Subject: file processing...
  5. Date: 21 Mar 1996 06:00:08 GMT
  6. Organization: University of Pennsylvania
  7. Message-ID: <4iqr98$i3p@netnews.upenn.edu>
  8. NNTP-Posting-Host: red.seas.upenn.edu
  9. X-Newsreader: TIN [version 1.2 PL2-upenn1.3]
  10.  
  11. I want to read the 1st line of a text file into an array. The only way I know of to 
  12. detect the end of a line is by checking for "\n", but the code I wrote does not seem 
  13. be detecting it. Here is the code...
  14.  
  15. #include<fstream.h>
  16. #include<iostream.h>
  17. #include<String.h>
  18.  
  19. int readf(char array[],char *);
  20. int readf (char array[], char *filename)
  21. {
  22.   int i=0;
  23.   char c;
  24.  
  25.   ifstream inFile(filename, ios::in);
  26.   while (inFile >> c)
  27.     if (c!="\n")      /*This line is giving me problem. It doesn't even compile */
  28.       array[i++]=c;
  29.     else
  30.       break;
  31.   return i;
  32.  
  33. }
  34.  
  35. void main(int argc,char *argv[])
  36. {
  37.   int i;
  38.   char array[50];
  39.   i=readf(array,"gro");
  40.  
  41.   for(int c=0;c<i;c++)
  42.     cout<<array[c];
  43.   cout<<"\n";
  44. }
  45.  
  46. --
  47.